<template>
    <div id="welfare">
        <el-row :gutter="20">
            <el-col :span="15">
                <el-form ref="form" :model="form" label-width="300px" size="small">
                    <el-form-item :label="this.$store.state.name+'说明'">
                        <quill-editor
                                v-model="form.coinesc"
                                ref="myQuillEditor"
                                :options="editorOption">
                        </quill-editor>
                    </el-form-item>
                    <el-form-item :label="'手机绑定赠送'+this.$store.state.name">
                        <el-input v-model="form.mobile"></el-input>
                    </el-form-item>
                    <el-form-item :label="'分享赠送'+this.$store.state.name">
                        <el-input v-model="form.sharemoney"></el-input>
                    </el-form-item>
                    <el-form-item :label="'注册起前几天可领取'+this.$store.state.name">
                        <el-input v-model="form.weekly_coin"></el-input>
                        <span class="input_hint">多个请以英文逗号,隔开</span>
                    </el-form-item>

                    <el-form-item label="'用户每日加入书架可领取'+this.$store.state.name">
                        <el-input v-model="form.join_bookshelves_coin"></el-input>
                    </el-form-item>
                    <el-form-item label="用户可提现金额">
                        <el-input v-model="form.withdraw_money"></el-input>
                        <span class="input_hint">多个请以英文逗号,隔开</span>
                    </el-form-item>
                    <el-form-item :label="'用户提现比例 元:'+this.$store.state.name">
                        <el-input v-model="form.withdraw_rate"></el-input>
                    </el-form-item>
                    <el-form-item label="每日观看视频限值">
                        <el-input v-model="form.daily_watch_video_times"></el-input>
                    </el-form-item>
                    <el-form-item :label="'每日观看视频'+this.$store.state.name">
                        <el-input v-model="form.daily_watch_video_coin"></el-input>
                    </el-form-item>
                    <el-form-item label="每章阅读时间标准限值（秒）">
                        <el-input v-model="form.each_chapter_read_time"></el-input>
                    </el-form-item>
                    <el-form-item label="幸运大转盘抽奖次数">
                        <el-input v-model="form.lucky_wheel_times"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">保存</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import quillConfig from '../../utils/quill-config.js'

    export default {
        name: "welfare",
        data() {
            return {
                form: {
                    coinesc: '',
                    mobile: '',
                    sharemoney: '',
                    weekly_coin: '',
                    join_bookshelves_coin: '',
                    withdraw_money: '',
                    withdraw_rate: '',
                    daily_watch_video_times: '',
                    daily_watch_video_coin: '',
                    each_chapter_read_time: '',
                    lucky_wheel_times: '',
                },
                editorOption: quillConfig,
            }
        },
        created() {
            this.getData()
        },
        methods: {
            onSubmit() {
                this.form = Object.assign(this.form, {key: 'welfare_center'});
                this.$axios.post('AdminApi/Config/ajaxSetValue', this.form).then((res) => {
                    this.$message('成功');
                });
            },
            getData() {
                this.$axios.post('AdminApi/Config/ajaxGetValue', {key: 'welfare_center'}).then((res) => {
                    this.form = res.data;
                    this.form.coinesc = this.html_decode(this.form.coinesc);
                });
            },
            html_decode(str) {
                var s = "";
                if (str.length == 0) return "";
                s = str.replace(/&amp;/g, "&");
                s = s.replace(/&lt;/g, "<");
                s = s.replace(/&gt;/g, ">");
                s = s.replace(/&nbsp;/g, " ");
                s = s.replace(/&#39;/g, "\'");
                s = s.replace(/&quot;/g, "\"");
                s = s.replace(/<br\/>/g, "\n");
                return s;
            }
        }
    }
</script>

<style scoped>

</style>